package com.project.service.impl;

import com.project.bean.ClassBean;
import com.project.mapper.IClassMapper;
import com.project.service.IClassService;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class ClassServiceImpl extends BaseService implements IClassService {
    @Override
    public List<ClassBean> findAll() {
        SqlSession session = this.getSession();
        IClassMapper mapper = session.getMapper(IClassMapper.class);
        List<ClassBean> list = mapper.findAll();
        session.close();
        return list;
    }

    @Override
    public void add(ClassBean classBean) {
        SqlSession session = this.getSession();
        IClassMapper mapper = session.getMapper(IClassMapper.class);
        mapper.add(classBean);
        session.commit();
        session.close();
    }

    @Override
    public boolean del(Integer classId) {
        SqlSession session = this.getSession();
        IClassMapper mapper = session.getMapper(IClassMapper.class);
       Integer classNum = mapper.findByClassId(classId);
            if (classNum==0){
                mapper.del(classId);
                session.commit();
                session.close();
                return true;
            }else {
                return false;
            }
    }
}
